/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bionic.ce.entitybeans.bankacc;

import com.bionic.ce.entities.Bankacc;
import com.bionic.ce.entitybeans.AbstractFacade;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

/**
 *
 * @author Jarik
 */
@Stateless
public class BankAccFacade extends AbstractFacade<Bankacc> implements BankAccFacadeLocal {

    @PersistenceContext(unitName = "Currency_ExchangeEE-PU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public BankAccFacade() {
        super(Bankacc.class);
    }

    @Override
    public List<Bankacc> findByUserIdAndCurrency(Integer userId, String currency) {
        String queryString = "SELECT b FROM Bankacc b WHERE userid=" + userId;
        String addQueryCurrency = " AND currency=\'" + currency+"\'";
        if (currency != null) {
            queryString += addQueryCurrency;
        }
        TypedQuery<Bankacc> query = em.createQuery(queryString, Bankacc.class);

        List<Bankacc> bankacclist = null;
        try {
            bankacclist = query.getResultList();
        } catch (NoResultException e) {
            e.printStackTrace();
        }
        return bankacclist;
    }
}
